<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.form.formfield');
class JFormFieldComponentsField extends JFormField
{
	/**
	 * The form field type.
	 *
	 * @var		string
	 * @since	1.6
	 */
	protected $type = 'ComponentsField';

	/**
	 * Method to get the field input markup.
	 *
	 * @return	string	The field input markup.
	 * @since	1.6
	 */
	protected function getInput()
	{
		$components = array();
		jimport('joomla.plugin.helper');
		$plugins = JPluginHelper::getPlugin('rssearch');

		$result = '<style type="text/css" media="screen">
				div#rsf_compfields label {
					float:left;
					clear:none;
					width:100px;
					display:block;
					margin-left:10px;
					line-height:21px;
					min-width:0px;
				}
				div#rsf_compfields {
					width:520px;
					float:left;
				}
			</style>
			<div id="rsf_compfields">';
			
			foreach($plugins as $plugin){
				$components[$plugin->name] = $plugin->name;
			}
			foreach( $components as $component => $component_name){
				
				if(is_array($this->value)){
					if(in_array($component, $this->value)){
						$result .= '<label><input checked="checked" type="checkbox" name="'.$this->name.'['.$component.']" value="'.$component.'" /> '.$component_name.'</label>';
					} else {
						$result .= '<label><input type="checkbox" name="'.$this->name.'['.$component.']" value="'.$component_name.'" /> '.$component_name.'</label>';
					}
				} elseif ($this->value) {
					if( $this->value == $component){
						$result .= '<label><input checked="checked" type="checkbox" name="'.$this->name.'['.$component.']" value="'.$component.'" /> '.$component_name.'</label>';
					} else {
						$result .= '<label><input type="checkbox" name="'.$this->name.'['.$component.']" value="'.$component.'" /> '.$component_name.'</label>';
					}
				} elseif (!($this->value )){
						$result .= '<label><input type="checkbox" name="'.$this->name.'['.$component.']" value="'.$component.'" /> '.$component_name.'</label>';
				}
			}
		$result .= "</div>";
		return $result;
	}
}
?>